stNode *cur = headA;/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) 
    {
        int counta = 0;
        int countb = 0;

        ListNode *cur = headA;
        ListNode *cur2 = headB;


        while(cur)
        {
            counta++;
            cur = cur->next;
        }

        while(cur2)
        {
            countb++;
            cur2 = cur2->next;
        }

        if (counta > countb)
        {
            int n = counta - countb;
            while(n--)
            {
                headA = headA->next;
            }
        }

        if (countb > counta)
        {
            int n = countb - counta;
            while(n--)
            {
                headB = headB ->next;
            }
        }


        while(headA)
        {
            if (headA == headB)
            {
                return headA;
            }
            headA = headA->next;
            headB = headB->next;
        }

        return NULL;


           
    }
};
